package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Caringwelfare.CaringwelfareActivity;
import com.example.myapplication.Cat.CatActivity;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.Garbagesorting.GarbageActivity;
import com.example.myapplication.Intelligent.IntelligentcontrolActivity;
import com.example.myapplication.Jobsearch.JobsearchActivity;
import com.example.myapplication.Outpatientappointment.OutpatientActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.Re_Servlet;
import com.example.myapplication.SmartElderly.SmartElderlyActivity;
import com.example.myapplication.carinspection.CarinspectionActivity;
import com.example.myapplication.dataanalysis.DataanalysisActivity;
import com.example.myapplication.government.GovernmentMainActivity;
import com.example.myapplication.hospital.PethospitalActivity;
import com.example.myapplication.house.HouseActivity;
import com.example.myapplication.lawyer.LawyerActivity;
import com.example.myapplication.library.LibraryMainActivity;
import com.example.myapplication.logisticsinquiry.LogisticsinquiryActivity;
import com.example.myapplication.management.ManagementActivity;
import com.example.myapplication.movie.MovieActivity;
import com.example.myapplication.subsistencepayment.SubsistencepaymentActivity;
import com.example.myapplication.teenager.YouthStationActivity;
import com.example.myapplication.urbansubway.UrbansubwayActivity;
import com.example.myapplication.volunteerservice.Volunteer;
import com.google.gson.Gson;

import java.util.List;

import smartbus.SmartbusActivity;
import takeout.TakeoutActivity;

public class CatrApter extends RecyclerView.Adapter<CatrApter.MyServer> {
    private Context context;
    private List<Re_Servlet.RowsDTO> list;
    private View view;
    private String TAG = "TAG";

    public CatrApter(Context context, List<Re_Servlet.RowsDTO> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<Re_Servlet.RowsDTO> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyServer onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        view = LayoutInflater.from(context).inflate(R.layout.item_catr, null);
        return new CatrApter.MyServer(view);
    }


    @Override
    public void onBindViewHolder(@NonNull MyServer holder, int position) {

        Glide.with(context).load(TokenBean.IP + list.get(position).getImgUrl()).into(holder.sever_tv_img);
        holder.sever_iv_text.setText(list.get(position).getServiceName());


        //数据分析
        if (list.get(position).getId() == 27) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, DataanalysisActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //智慧养老
        if (list.get(position).getId() == 188) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, SmartElderlyActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //外卖
        if (list.get(position).getId() == 19) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, TakeoutActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //找工作
        if (list.get(position).getId() == 21) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, JobsearchActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //智慧交管
        if (list.get(position).getId() == 7) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, SubsistencepaymentActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //智慧交管
        if (list.get(position).getId() == 9) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, IntelligentcontrolActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //物流查询
        if (list.get(position).getId() == 24) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LogisticsinquiryActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //停那儿
        if (list.get(position).getId() == 17) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, CatActivity.class);
                    context.startActivity(intent);
                }
            });
        }
        //青年驿站
        if (list.get(position).getId() == 26) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, YouthStationActivity.class);
                    context.startActivity(intent);
                }
            });
        }
        //活动管理
        if (list.get(position).getId() == 22) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, ManagementActivity.class);
                    context.startActivity(intent);
                }
            });
        }
        //爱心捐赠
        if (list.get(position).getId() == 25) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, CaringwelfareActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //政府服务
        if (list.get(position).getId() == 29) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, GovernmentMainActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //图书馆
        if (list.get(position).getId() == 30) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LibraryMainActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //找房子
        if (list.get(position).getId() == 20) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, HouseActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //点击进入门诊预约
        if (list.get(position).getId() == 5) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, OutpatientActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //点击进入垃圾分类
        if (list.get(position).getId() == 31) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, GarbageActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //律师
        if (list.get(position).getId() == 99) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LawyerActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //智慧巴士
        if (list.get(position).getId() == 3) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, SmartbusActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //预约检车
        if (list.get(position).getId() == 88) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, CarinspectionActivity.class);

                    context.startActivity(intent);
                }
            });
        }


        //看电影
        if (list.get(position).getId() == 18) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, MovieActivity.class);
                    context.startActivity(intent);
                }
            });
        }


        //志愿服务
        if (list.get(position).getId() == 32) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, Volunteer.class);
                    context.startActivity(intent);
                }
            });
        }

        //宠物医院
        if (list.get(position).getId() == 23) {

            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, PethospitalActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        //城市地铁
        if (list.get(position).getId() == 2) {
            holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, UrbansubwayActivity.class);
                    context.startActivity(intent);
                }
            });
        }

    }

    @Override
    public int getItemCount() {

        return list == null ? 0 : list.size();

    }

    class MyServer extends RecyclerView.ViewHolder {

        private final RecyclerView recyclerView;
        private final TextView sever_iv_text;
        private final ImageView sever_tv_img;

        public MyServer(@NonNull View itemView) {
            super(itemView);
            recyclerView = itemView.findViewById(R.id.rcy_service);
            sever_iv_text = itemView.findViewById(R.id.sever_iv_text);
            sever_tv_img = itemView.findViewById(R.id.sever_tv_img);

        }
    }
}

